package mtn.lgdx.GPS;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.net.*;
import com.tencent.mm.sdk.openapi.*;
import com.tencent.mm.sdk.modelmsg.*;
import android.graphics.*;
import java.io.*;
import com.tencent.mm.sdk.modelbase.*;
import mtn.lgdx.GPS.wxapi.*;
import android.content.res.*;

public class AboutActivity extends Activity implements View.OnClickListener {

	private Button btn1 = null, btn2 = null, btn3 = null; //done/feedback/share
	/*微信接口*/
	private IWXAPI api; //第三方app与微信通信的openapi接口

	@Override
	public void onClick(View p1) {
		// TODO: Implement this method
		switch (p1.getId()) {
		case R.id.done:
			//done
			super.onBackPressed();
			break;
		case R.id.feedback:
			//feedback
				Intent data = new Intent(Intent.ACTION_SENDTO);
				data.setData(Uri.parse("mailto:hele-two@163.com"));
				data.putExtra(Intent.EXTRA_SUBJECT, "关于" + getResources().getString(R.string.app_name)+"的反馈");
				data.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.version));
				startActivity(data);
			break;
		case R.id.share:
			share();
			break;
		}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTheme(Utils.getTheme());
		setContentView(R.layout.about);
		btn1 = (Button)findViewById(R.id.done);
		btn2 = (Button)findViewById(R.id.feedback);
		btn3 = (Button)findViewById(R.id.share);
		btn1.setOnClickListener(this);
		btn2.setOnClickListener(this);
		btn3.setOnClickListener(this);
		
		String APP_ID = getResources().getString(R.string.wxID);
		api = WXAPIFactory.createWXAPI(this, APP_ID); //初始化api
		api.registerApp(APP_ID); //将APP_ID注册到微信中
	}

	private void share() {
		if (!api.isWXAppInstalled()) {
			Toast.makeText(this, "您还未安装微信客户端", Toast.LENGTH_LONG).show(); 
			return;
		}
		WXWebpageObject webpage =new WXWebpageObject(getResources().getString(R.string.url));
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = getResources().getString(R.string.version) + ",小伙伴们快来！";
		// 缩略图
		Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.share);
	//	Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap,108, 108, true);
		msg.setThumbImage(bitmap);
	
		//创建一个用于请求微信客户端的SendMessageToWX对象
		SendMessageToWX.Req req =new SendMessageToWX.Req();
		//transaction字段用于唯一标识一个请求，这个必须有，否则会出错
		req.transaction = "WEBPAGE" + System.currentTimeMillis();
		req.message = msg;
		req.scene = SendMessageToWX.Req.WXSceneTimeline;
		api.sendReq(req);
	}

}
